package com.ruoyi.ui.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ui.domain.UiBanner;
import com.ruoyi.ui.service.IUiBannerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 轮播图Controller
 * 
 * @author ruoyi
 * @date 2022-09-06
 */
@RestController
@RequestMapping("/banner")
public class UiBannerController extends BaseController
{
    @Autowired
    private IUiBannerService uiBannerService;

    /**
     * 查询轮播图列表
     */
    @RequiresPermissions("ui:banner:list")
    @GetMapping("/list")
    public TableDataInfo list(UiBanner uiBanner)
    {
        startPage();
        List<UiBanner> list = uiBannerService.selectUiBannerList(uiBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @RequiresPermissions("ui:banner:export")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UiBanner uiBanner)
    {
        List<UiBanner> list = uiBannerService.selectUiBannerList(uiBanner);
        ExcelUtil<UiBanner> util = new ExcelUtil<UiBanner>(UiBanner.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    @RequiresPermissions("ui:banner:query")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return AjaxResult.success(uiBannerService.selectUiBannerByBannerId(bannerId));
    }

    /**
     * 新增轮播图
     */
    @RequiresPermissions("ui:banner:add")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UiBanner uiBanner)
    {
        return toAjax(uiBannerService.insertUiBanner(uiBanner));
    }

    /**
     * 修改轮播图
     */
    @RequiresPermissions("ui:banner:edit")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UiBanner uiBanner)
    {
        return toAjax(uiBannerService.updateUiBanner(uiBanner));
    }

    /**
     * 删除轮播图
     */
    @RequiresPermissions("ui:banner:remove")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(uiBannerService.deleteUiBannerByBannerIds(bannerIds));
    }
}
